﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DataBase;

public class Data : MonoBehaviour
{
    #region 单例模式
    private static Data _instance=null;
    public static Data Instance
    {
        get
        {
            if(_instance==null)
            {
                _instance = GameObject.FindObjectOfType<Data>();
                if(_instance==null)
                {
                    GameObject go = new GameObject("Data");
                    _instance = go.AddComponent<Data>();
                }                    
            }
            return _instance;
        }
    }

    private void DanAwake()
    {
        if (_instance == null)
            _instance = this;
        else
            Destroy(gameObject);

        DontDestroyOnLoad(this.gameObject);
        Dialogue.initData();
    }
    #endregion

    /// <summary>
    /// 储存场景中存在的所有怪物
    /// </summary>
    public List<GameObject> monster = new List<GameObject>();

    private void Awake()
    {
        DanAwake();
        DataInit();
        BinInit();
    }

    void DataInit()
    {
        EventCenter.AddListener<GameObject>(MyEventType.MonsterRegiste, MonsterRigister);
    }

    void MonsterRigister(GameObject _monster)
    {
        monster.Add(_monster);
    }

    /// <summary>
    /// 初始化二进制表格数据
    /// </summary>
    void BinInit()
    {
        Skill.initData();
    }
}
